package com.ebupt.migu.music.commons.selfdom.demo.impl;

import com.ebupt.migu.globalpopup.entity.ConditionRelation;
import com.ebupt.migu.globalpopup.enums.ConditionEnum;
import com.ebupt.migu.music.commons.selfdom.demo.Growth;
import com.ebupt.migu.music.commons.selfdom.demo.impl.identifier.AbstractIdentifierImpl;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * 成长条件实现类
 *
 * @author wangzhu
 * @since 2021-12-31
 */
public class GrowthImpl extends AbstractIdentifierImpl implements Growth {
    /**
     * Lv.1-Lv.n
     */
    private boolean lv(String data, ConditionRelation conditionRelation,Integer conditionKey) {
        return super.getIdentifier(data, conditionRelation.getConditionData(), conditionRelation.getRelation(),conditionKey);
    }

    /**
     * 更具不同的子条件判断返回判断结果（子条件第一版只支持or）
     */
    @Override
    public boolean getGrowth(Map data, List<ConditionRelation> conditionRelations) {
        LinkedHashMap<Boolean, Integer> booleanIntegerLinkedHashMap = new LinkedHashMap<>();
        // 排序
        super.sort(conditionRelations);
        for (ConditionRelation conditionRelation : conditionRelations) {
            boolean l = true;
            Object o = data.get(ConditionEnum.getKeyValue(conditionRelation.getPropertyCode(), conditionRelation.getConditionKey()));
            if (o==null||o.equals("")) {
                l=false;
                booleanIntegerLinkedHashMap.put(l,conditionRelation.getCConnector());
                break;
            }
            String value = o.toString();
            switch (conditionRelation.getConditionKey()) {
                case 1:
                    l = this.lv(value, conditionRelation,conditionRelation.getConditionKey());
                    break;
                default:
                    break;
            }
            booleanIntegerLinkedHashMap.put(l,conditionRelation.getCConnector());
        }
        return super.getRelation(booleanIntegerLinkedHashMap);
    }
}
